package com.mark.web.data.entity.vo;

import com.mark.web.data.entity.po.HeadLine;
import com.mark.common.utils.DateTimeUtil;
import com.mark.common.utils.PropertiesUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Date;

/**
 * @Description: 公告头条信息的VO封装
 * @Author: Mark
 * @CreateDate: 2018/5/15.
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class HeadLineVo {
    private Integer lineId;         //ID
    private String lineName;        //描述
    private String lineLink;        //链接
    private Integer enableStatus;   //状态【0：不可用】【1：可用】
    private String statusDes;       //状态描述
    private Integer priority;       //权重
    private String createTime;      //创建时间
    private String lastEditTime;    //最后的编辑时间
    private String imageHost;       //URL
    private Integer totalDays;      //统计发布的天数

    public HeadLineVo assembleHeadLineVo(HeadLine headLine){
        HeadLineVo headLineVo = new HeadLineVo();
        headLineVo.setLineId(headLine.getLineId());
        headLineVo.setLineName(headLine.getLineName());
        headLineVo.setLineLink(headLine.getLineLink());
        headLineVo.setEnableStatus(headLine.getEnableStatus());
        String statusDes = this.assembleStatus(headLine.getEnableStatus());
        headLineVo.setStatusDes(statusDes);
        headLineVo.setPriority(headLine.getPriority());
        headLineVo.setCreateTime(DateTimeUtil.dateToStr(headLine.getCreateTime()));
        headLineVo.setLastEditTime(DateTimeUtil.dateToStr(headLine.getLastEditTime()));
        headLineVo.setTotalDays(DateTimeUtil.dayBetween(headLine.getCreateTime(),new Date()));
        headLineVo.setImageHost(PropertiesUtil.getProperty("ftp.server.http.prefix",PropertiesUtil.FTP_SERVER_HTTP_PREFIX));
        return headLineVo;
    }

    private String assembleStatus(Integer enableStatus) {//组装头条的状态描述
        switch (enableStatus){
            case 0 : return "已下架";
            case 1 : return "使用中";
            default: return "不明确";
        }
    }

}
